<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
<#assign base=request.contextPath  />
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <link rel="stylesheet" href="${base}/frame/static/css/style.css">
    <link rel="icon" href="${base}/frame/static/image/code.png">
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script type="text/javascript" src="${base}/frame/layui/layui.all.js"></script>
    <script src="${base}/js/jquery-1.8.3.min.js"></script>
</head>
<boby class="body">
	<div class="demoTable" style="padding:10px;">
            <div class="layui-inline">
                <input class="layui-input" style="height: 31px;" name="id" id="demoReload" autocomplete="off">
            </div>
            <button class="layui-btn layui-btn-sm layui-btn-normal" id="btn1" data-type="reload" >
                搜索
            </button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" id="btn2" data-method="offset" type="button">添加角色
        </button>
    </div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<#--<script type="text/html" id="barDemo">-->
<#--<i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="edit" href="javascript:void(0)"  onclick="delectRole('{{d.id}}')"  style="font-size: 20px;" ></i>-->
<#--</script>-->
<script type="text/html" id="barDemo">
    <betton class="layui-btn layui-btn-danger layui-btn-xs " lay-event="edit" onclick="delectRole('{{d.id}}')">删除
    </betton>
</script>
<script src="${base}/js/layui/layui.js"></script>
<script>
    layui.use(['form', 'layer', 'laydate', 'table'], function () {
        var form = layui.form
                , $ = layui.jquery
                , layer = layui.layer
                , laydate = layui.laydate
                , table = layui.table;
        table.render({
            elem: '#test'
            , toolbar: '#toolbarDemo'
            , size: 'sm'
             ,title: '用户数据表'
            , url: '${base}/comUser/userAdminList'
            , cols: [[
                {field: 'username',align: 'center', title: '序号', width: 80,
                     templet: function (val) {
                        return val.LAY_INDEX
                    }
                }
                , {field: 'callPhone', title: '登录手机号',width:300, align: 'center'}
                , {field: 'roleName',title: '角色', align: 'center', templet: function (val) {
                        if (val.roleName == "" || val.roleName == null) {
                            return "无";
                        } else {
                            return val.roleName;
                        }
                    },
                }
//      ,{field:'createTime', align: 'center',templet:function(val){
//              return changeDateFormat(val.createTime)
//          }, title: '创建时间'}
                , {field: 'eczxxxxema', title: '操作', align: 'center',width:200, toolbar: '#barDemo'}
            ]]
            , id: 'testReload'
            ,height:480
            ,page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']
                ,theme: '#9AC747'
                ,limit: 10
            }, done: function (res, curr, count) {
                this.where = {};
            }
        });
        $('#btn1').on('click', function () {
            var whereData = {};
            whereData.roleName = Trim($("#demoReload").val())
            var table = layui.table;
            //表刷新方法
            table.reload('testReload', {
                url: '${base}/comUser/userAdminList'
                , where: whereData
            });

        });
        var active = {
            offset: function (othis) {
                var type = othis.data('type')
                        , text = othis.text();
                layer.open({
                    type: 2,
                    title: '添加角色',

                    shadeClose: false,
                    area: ['560px', '560px'],
                    content: '${base}/comUser/updateUser.html',
                    success: function (layero, index) {
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    }
                });
            }
        };
        $('#btn2').on('click', function () {
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
    });

    function delectRole(id) {

        layer.confirm('真的要删除吗?', function (index) {
            $.ajax({
                type: "POST",
                url: "${base}/comUser/deleteUser",
                data: {"id": id},
                success: function (data) {
                    layer.msg(data)
                    var table = layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/comUser/userAdminList'
                        , where: {} //设定异步数据接口的额外参数
                    });
                    layer.close(index);
                }
            });

        });
    }
</script>
</body>
</html>